// pages/tabar.js
Component({
  properties: {
    itemIndex: {
      type: Number,
      value: 0
    },
  },
  /**
   * 页面的初始数据
   */
  data: {
    // role:2,
    tablist1: [{
        "text": "首页",
        // "iconPath": "../../assets/tabs/zyzt_n.png",
        // "selectedIconPath": "../../assets/tabs/zyzt.png",
        "iconPath": "../../assets/tab-home.png",
        "selectedIconPath": "../../assets/tab-home-current.png",
        "url": "/pages/index/index",
        'show': true,
        'role': 'student', //0或者其他
        'activeIndex': 0,
        'isLogin': false
      },
      {
        "text": "首页",
        "iconPath": "../../assets/tab-home.png",
        "selectedIconPath": "../../assets/tab-home-current.png",
        "url": "/pages/index/index",
        'show': true,
        'role': "teacher", //0或者其他
        'activeIndex': 1,
        'isLogin': false

      },

      {
        "text": "我的",
        "selectedIconPath": "../../assets/tab-my-current.png",
        "iconPath": "../../assets/tab-my.png",
        "url": "/pages/studentPerson/index",
        'show': false,
        'role': 'student', //0或者其他
        'activeIndex': 4,
        'isLogin': false
      },

      {
        "text": "我的",
        "selectedIconPath": "../../assets/tab-my-current.png",
        "iconPath": "../../assets/tab-my.png",
        "url": "/pages/teacherPerson/index",
        'show': false,
        'role': 'teacher', //0或者其他
        'activeIndex': 4,
        'isLogin': false
      }
    ],
    tablist2: [

      {
        "text": "消息列表",
        "iconPath": "../../assets/tabs/message_n@2x.png",
        "selectedIconPath": "../../assets/tabs/message_y@2x.png",
        'show': true,
        "num": 0
      },

      {
        "text": "个人中心",
        "iconPath": "../../assets/tabs/sy_me_n.png",
        "selectedIconPath": "../../assets/tabs/me.png",
        'show': false,
        "num": 1
      }
    ],
    acount: '',
    token: ""
  },

  ready: function() {
    let that = this

    wx.getStorage({
      key: 'wxinfo',
      success(res) {
        that.getMessageCount()
      }
    })

    that.init();
  },

  methods: {
    init() {
      var role = wx.getStorageSync("role")
      var tmp = []

      tmp = this.data.tablist1.filter(function(item) {
        return item.role == role
      })

      this.setData({
        tablist1: tmp
      })

    },

    onTabbarItemTap(e) {
      var index = e.currentTarget.dataset.index
      var activeIndex = e.currentTarget.dataset.activeIndex;
      var url = e.currentTarget.dataset.url;
      this.setData({
        itemIndex: index,

      })
      wx.reLaunch({
        // url: '../my/my',
        url: url,
      })

    },
  }
})